from django.apps import AppConfig
import os

class PhaseSummaryConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'phase_summary'
    verbose_name = '报告管理'

    def ready(self):
        """应用启动时执行"""
        # 手动设置环境变量
        os.environ['RUNSERVER'] = 'true'

        # 只在设置了 RUNSERVER 环境变量时执行初始化
        if os.getenv('RUNSERVER') == 'true':
            from celery import current_app
            print("\n=== PhaseSummary 应用启动 ===")
            current_app.send_task('phase_summary.tasks.generate_initial_reports')

